package com.twu.biblioteca;

import java.util.ArrayList;

/**
 * Created by theyes on 17/01/2014.
 */
public class ReturnMovieMenu extends ReturnItemMenu {


    public ReturnMovieMenu(MockItemDataBase DB) {
        super(DB);
    }

    @Override
    public void attemptReturnItem() {

        String name = askUserForMovieName();
        String director = askUserForMovieDirector();
        int year = askUserForMovieYear();

        validateMovieDetailForReturn(name,director,year);

    }

    private void validateMovieDetailForReturn(String name, String director, int year) {
        ArrayList<LibraryItem> allMovies = itemDB.getAllItems();

        for(int i =0; i < allMovies.size(); i++)
        {
            Movie workingMovie = (Movie) allMovies.get(i);
            if(workingMovie.director.equals(director) && workingMovie.name.equals(name) && workingMovie.year==year)
            {
                workingMovie.checkIn();
                System.out.println("Thank you for returning the movie.");
                return;
            }
        }
        System.out.println("That is not a valid movie for return.");

    }

    private String askUserForMovieName()
    {
        System.out.println("What is the name of the movie?");
        return userInputHandle.readInput();
    }

    private String askUserForMovieDirector() {
        System.out.println("Who directed the movie?");
        return userInputHandle.readInput();
    }

    private int askUserForMovieYear() {
        System.out.println("What year was the movie released?");
        return userInputHandle.readInputInt();
    }

}
